package com.crm.controller;


import com.crm.common.result.AjaxResult;
import com.crm.common.result.Result;

import com.crm.domain.Dept;
import com.crm.domain.DeptTreeResult;
import com.crm.dto.DeptListDto;
import com.crm.dto.Vo.DeptTreeVo;
import com.crm.service.DeptService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/system/dept")
@RequiredArgsConstructor
public class DeptController {
    //部门管理
    @Autowired
    private DeptService deptService;
    /**
     * 部门下拉树列表
     */
    @GetMapping("/treeselect")
    public Result<List<DeptTreeVo>> treeSelect() {
        return Result.success(deptService.treeSelect());
    }


    @PutMapping()
    public AjaxResult update(@RequestBody Dept dept) {
        log.info("修改部门参数: {}", dept);
        return deptService.updateDept(dept);
    }

    @PostMapping()
    public AjaxResult save(@RequestBody Dept dept) {
        log.info("新增部门参数: {}", dept);
         deptService.addDept(dept);
        return AjaxResult.success();
    }


    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {
        log.info("删除部门id参数: {}", id);
        return deptService.deleteDept(id);
    }

    @GetMapping("/{id}")
    public AjaxResult get(@PathVariable("id") Long id) {
        log.info("获取部门id详情参数: {}", id);
        return deptService.queryDept(id);
    }

@GetMapping("/list")
public AjaxResult list(DeptListDto dto) {
    log.info("部门查询参数: {}", dto);
    return deptService.queryDeptList(dto);
}

    @GetMapping("/roleDeptTreeselect/{roleId}")

    public DeptTreeResult roleDeptTreeselect(@PathVariable("roleId") Long roleId) {
        log.info("获取角色拥有的部门树参数: {}", roleId);
        return deptService.roleDeptTreeselect(roleId);
    }


}








